#include  "ac.h"
#include	"adc.h"
#include  "can.h"
#include  "PTC.h"
#include  "BMS.h"
#include	"key.h"
#include  "load.h"
#include 	"init.h"
#include 	"main.h"
#include	"error.h"
#include 	"blower.h"
#include	"system.h"
#include  "switch.h"
#include 	"display.h"
#include  "program.h"
#include  "fanmotor.h"
#include 	"interrupt.h"
#include 	"elestepmotor.h"
/*
main
*/
void System_Intgnd(void)
{	
	if(F_Time_1ms)				
	{
		F_Time_1ms = 0;
		
		Get_ShortKeyValue();
	}
	if(F_Time_5ms)				
	{
		F_Time_5ms = 0;
		Get_ADCDigitalValue();
	}
	if(F_Time_10ms)				
	{
		F_Time_10ms = 0;

		CAN1_TXPackage();
		
		Ctrl_FanMotor();
		
		Get_FrontTempBlockValue();
		Get_BackTempBlockValue();
		Get_BMSTempBlockValue();
		
		Get_FrontSetModeValue();
		Get_BackSetModeValue();
		
		Set_ACParameter();
		Set_LcdDisplay();
		Set_LedDisplay();
		
		Ctrl_Relay();
		
		Ctrl_FrontEvapFan();
		Ctrl_FrontCondFan();
		
		Ctrl_BackEvapFan();
		Ctrl_BackCondFan();
		
		Get_BMSSetModeValue();
		Ctrl_WaterPump();
		Ctrl_BMSPTC();
		
		if(FrontAirconditionStepCnt)
			FrontAirconditionStepCnt--;
		if(BackAirconditionStepCnt)
			BackAirconditionStepCnt--;
		if(BMSAirconditionStepCnt)
			BMSAirconditionStepCnt--;
		
		if(Aircondition.DlyCleanFrontCoolNeed)
			Aircondition.DlyCleanFrontCoolNeed--;
	}
	if(F_Time_33ms)		   
	{
		F_Time_33ms = 0;

	}
	if(F_Time_50ms)		   
	{
		F_Time_50ms = 0;
		
		CAN0_TXPackage();
		
		if(Aircondition.AskCtrlTyped == 1)
		{
			if(CAN1_TXPointer<CAN1_NUMBER)
			{
				CAN1_VersionPackage(CAN1_TxMessage+CAN1_TXPointer);		
				CAN1_TXPointer++;
			}
		}
	}
	if(F_Time_100ms)		   
	{
		F_Time_100ms = 0;
		
		Get_ADCAnalogValue();
		
		Flash_WriteValue();
		
		Get_ErrorState();
		Get_SwitchState();
		
		Get_BackDefrostStatus();
		Get_FrontDefrostStatus();
		
		Get_FrontEvapFanLevel();
		Get_BackEvapFanLevel();

		if(CAN0_TXPointer<CAN0_NUMBER)
		{
			CAN0_PDO1Package(CAN0_TxMessage+CAN0_TXPointer);		
			CAN0_TXPointer++;
		}	
		if(Aircondition.BackAIRCmd == ENABLE)
		{
			if(CAN0_TXPointer<CAN0_NUMBER)
			{
				CAN0_PDO2Package(CAN0_TxMessage+CAN0_TXPointer);		
				CAN0_TXPointer++;
			}	
	}
		if(CAN0_TXPointer<CAN0_NUMBER)
		{
			CAN0_PDO3Package(CAN0_TxMessage+CAN0_TXPointer);		
			CAN0_TXPointer++;
		}	
		
		Aircondition.LongKeyTime = 1;
	}
	if(F_Time_500ms)			
	{
		F_Time_500ms = 0;
		
		Get_LongKeyValue();	 
		Get_FrontInTempUpDownState();
		Get_BackInTempUpDownState();
		
		Set_ACAskAndEnable();
		Set_PTCAskAndEnable();
		
		if(CAN0_TXPointer<CAN0_NUMBER)
		{
			CAN0_PDO4Package(CAN0_TxMessage+CAN0_TXPointer);		
			CAN0_TXPointer++;
		}	
		
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_PDO1Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_PDO6Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_PDO7Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_BMS1Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_BMS2Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_BMS3Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}
	}	
	if(F_Time_1000ms)				
	{
		F_Time_1000ms = 0;

		AC_Power();
		
		Set_FanMotorAngle();
		
		Set_FrontACSpeed();
		Set_FrontPTCPower();
		
		Set_BackACSpeed();
		
		Ctrl_MainEleWay();
		Ctrl_BMSStepMotor();
		
		F_Flash_Fg = ~F_Flash_Fg;
		
	  if(FrontAC_Off_Cycle)
			FrontAC_Off_Cycle--;
		if(FrontPTC_Off_Cycle)
			FrontPTC_Off_Cycle--;
		if(BackAC_Off_Cycle)
			BackAC_Off_Cycle--;
		
		if(Aircondition.FroceSetMode != NFORCE)
		{
			if(Aircondition.FroceModeTime)
				Aircondition.FroceModeTime--;
			else
				Aircondition.FroceSetMode = NFORCE;
		}
		else
			Aircondition.FroceModeTime = 5*60;
		
		if(Aircondition.BMS_DBGMode != NOFORCE)
		{
			if(Aircondition.BMS_DBGTime)
				Aircondition.BMS_DBGTime--;
			else
				Aircondition.BMS_DBGMode = NOFORCE;
		}
		else
			Aircondition.BMS_DBGTime = 15*60;
		
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_PDO2Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_PDO3Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}	
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_PDO4Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}
		if(CAN1_TXPointer<CAN1_NUMBER)
		{
			CAN1_PDO5Package(CAN1_TxMessage+CAN1_TXPointer);		
			CAN1_TXPointer++;
		}	
	}
	if(F_Time_10s)
	{
		F_Time_10s = 0;
	}
}

